package com.gzt.bookcatalog.service.search.impl;

import com.gzt.bookcatalog.dto.BookSearchDTO;
import com.gzt.bookcatalog.model.Book;
import com.gzt.bookcatalog.repository.BookRepository;
import com.gzt.bookcatalog.service.search.BookSearchStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

@Service
public class TitleSearchStrategy implements BookSearchStrategy {
    private final BookRepository bookRepository;

    @Autowired
    public TitleSearchStrategy(BookRepository bookRepository) {
        this.bookRepository = bookRepository;
    }

    @Override
    public Page<Book> search(BookSearchDTO searchDTO) {
        return bookRepository.findByTitleContainingIgnoreCase(searchDTO.getQuery(), searchDTO.toPageable());
    }
}